package LocationTimes

case class UserInfo(username:String,location:String,startTime:Int,duration:Int)

object LocationTimes extends App {
  val userInfoList:List[UserInfo]=List(
    UserInfo("userA", "locationA", 8, 60),
    UserInfo("userA", "locationA", 9, 60),
    UserInfo("userB", "locationB", 11, 80),
    UserInfo("userB", "locationB", 10, 60))

  val groupInfo: Map[String, List[UserInfo]] = userInfoList.groupBy(UserInfo => UserInfo.username + "-" + UserInfo.location)
  println(groupInfo)

  val sortInfo: Map[String, List[UserInfo]] = groupInfo.mapValues(_.sortBy(_.startTime))
  println(sortInfo)

  var startTime=0
  val sumUserInfo: Map[String, Int] = sortInfo.mapValues(list=>{
    startTime = list.head.startTime
    list.map(_.duration).sum
  })
  println(sumUserInfo)

  sumUserInfo.foreach{
    case (k,v)=>println(s"$k,$v,$startTime")
  }
}


